//import LRU from 'lru-cache'
import axios from 'axios'
const serverApi = axios.create({
  timeout: 15000,
  baseURL: 'http://node.zhuwenbo.cc',
  withCredentials: true,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  }
})
//添加自定义实例请求拦截器
serverApi.interceptors.request.use(
  config => config,
  error => {
    console.info(' >> 打印请求开始错误：', error)
  }
)
//添加自定义实例响应拦截器
serverApi.interceptors.response.use(
  response => {
    console.info(' >> 打印服务端返回数据：', response.data)
    return response.data
  },
  error => {
    console.info(' >> 打印请求返回错误：', error)
    return false
  }
)
let api
if (process.__API__) {
  api = process.__API__
} else {
  api = process.__API__ = serverApi

  // // fetched item cache
  // api.cachedItems = LRU({
  //   max: 1000,
  //   maxAge: 1000 * 60 * 15 // 15 min cache
  // })

  // // cache the latest story ids
  // api.cachedIds = {}
}

export default api